import java.util.Arrays;

public class FindRadius {

    public static void main(String[] args) {
        int[] houses = {1, 5};
        int[] heaters = {10};
        FindRadius findRadius = new FindRadius();
        System.out.println(findRadius.findRadius(houses, heaters));
    }

    public int findRadius1(int[] houses, int[] heaters) {
        int ans = 0;
        Arrays.sort(heaters);
        for (int i = 0; i < houses.length; i++) {
            int index = binarySearch(houses[i], heaters);
            int l = index == -1 ? Integer.MAX_VALUE : houses[i] - heaters[index];
            int r = index == heaters.length - 1 ? Integer.MAX_VALUE : heaters[index + 1] - houses[i];
            ans = Math.max(ans, Math.min(l, r));
        }
        return ans;
    }

    public int binarySearch(int target, int[] heaters) {
        int l = 0;
        int r = heaters.length - 1;
        if (heaters[0] > target) return -1;
        while (l < r) {
            int mid = (l + r + 1) / 2 ;
            if (heaters[mid] <= target) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        return l;
    }

    public int findRadius(int[] houses, int[] heaters) {
        Arrays.sort(houses);
        Arrays.sort(heaters);
        int ans = 0;
        for (int i = 0, j = 0; i < houses.length; i++) {
            int temp = Math.abs(houses[i] - heaters[j]);
            while (j < heaters.length - 1 && Math.abs(houses[i] - heaters[j]) >= Math.abs(houses[i] - heaters[j + 1])) {
                ++j;
                temp = Math.abs(houses[i] - heaters[j]);
            }
            ans = Math.max(ans, temp);
        }
        return ans;
    }
}
